
/**
  ******************************************************************************
  * Copyright 2021 The Microbee Authors. All Rights Reserved.
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  * 
  * http://www.apache.org/licenses/LICENSE-2.0
  * 
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  * 
  * @file       relay.h
  * @author     baiyang
  * @date       2023-9-18
  ******************************************************************************
  */

#pragma once

#ifdef __cplusplus
extern "C"{
#endif

/*----------------------------------include-----------------------------------*/
#include "relay_config.h"

#if MB_RELAY_ENABLED
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>

#include <gcs_mavlink/gcs.h>
#include <parameter/param.h>
/*-----------------------------------macro------------------------------------*/
#define MB_RELAY_NUM_RELAYS 6
/*----------------------------------typedef-----------------------------------*/
typedef struct mb_relay *mb_relay_t;

/** @ 
  * @brief  
  */
struct mb_relay {
    Param_int8 _pin[MB_RELAY_NUM_RELAYS];
    Param_int8 _default;
    uint8_t _pin_states;
    uint8_t _last_logged_pin_states;
    uint32_t _last_log_ms;
};
/*----------------------------------variable----------------------------------*/

/*-------------------------------------os-------------------------------------*/

/*----------------------------------function----------------------------------*/
void rly_ctor();
void rly_init();
void rly_on(uint8_t instance);
void rly_off(uint8_t instance);
uint8_t rly_get(uint8_t instance);
bool rly_enabled(uint8_t instance);
void rly_toggle(uint8_t instance);
bool rly_arming_checks(size_t buflen, char *buffer);
#if MB_MAVLINK_MSG_RELAY_STATUS_ENABLED
bool rly_send_relay_status(gcs_mavlink_t gcsmav);
#endif
/*------------------------------------test------------------------------------*/

#ifdef __cplusplus
}
#endif

#endif

